﻿using System.Collections.Generic;
using System.Linq;
using DocumentBuilder.Components;

namespace DocumentBuilder.Controls.DataSources.Collection
{
    public class ObjectCollection : IIterableDataSource<IDataItem>
    {
        private List<ViewObject> Data { get; set; }

        public ObjectCollection(string id, List<ViewObject> objectCollection)
        {
            Id = id;
            Data = objectCollection;
        }

        #region IControlDataSource Members

        public string Id { get; private set; }

        public string Eval(string evalPath)
        {
            return this.ToString();
        }

        #endregion

        #region IEnumerable<ViewObject> Members

        public IEnumerator<IDataItem> GetEnumerator()
        {
            var i = 0;
            return Data.Select(data => new ObjectDataItem(i++, data)).GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion
    }
}
